home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Examples / Nothing / Nothing.cp
Encoding:
Text File  |  1996-04-03  |  6.3 KB  |  231 lines  |  [TEXT/MPS ]

  1. //----------------------------------------------------------------------------------------
  2. // Nothing.cp
  3. // Copyright © 1986-96 by Apple Computer, Inc. All rights reserved.
  4. //----------------------------------------------------------------------------------------
  5.  
  6. /*
  7.     This is a very small sample application. The application's windows each contain
  8.     the word 'MacApp', in large type, and are framed by a large gray border. 
  9.     
  10.     All applications that create views procedurally need to reimplement at least
  11.     three methods:
  12.     
  13.         TApplication::DoMakeDocument    Launches the appropriate type of Document object
  14.         TDocument::DoMakeViews            Launches the appropriate type of View and window
  15.                                         objects
  16.         TView::Draw                        Draws the contents of a view
  17.     
  18.     This application, however, consists of the reimplementation of only one method, 
  19.     TView::Draw. This is possible since the view is created from templates; MacApp
  20.     supplies the default 'view' resource. So in a sense this application is the smallest
  21.     possible MacApp application.
  22. */
  23.  
  24. // MacApp
  25.  
  26. #ifndef __MACAPPTYPES__
  27. #include "MacAppTypes.h"
  28. #endif
  29.  
  30. #ifndef __UAPPLICATION__
  31. #include "UApplication.h"
  32. #endif
  33.  
  34. #ifndef __UDOCUMENT__
  35. #include "UDocument.h"
  36. #endif
  37.  
  38. #ifndef __UERRORMGR__
  39. #include "UErrorMgr.h"
  40. #endif
  41.  
  42. #ifndef __UMACAPPGLOBALS
  43. #include "UMacAppGlobals.h"
  44. #endif
  45.  
  46. #ifndef __UMACAPPUTILITIES__
  47. #include "UMacAppUtilities.h"
  48. #endif
  49.  
  50. #ifndef __UVIEW__
  51. #include "UView.h"
  52. #endif
  53.  
  54. // Toolbox
  55.  
  56. #ifndef __FONTS__
  57. #include <Fonts.h>
  58. #endif
  59.  
  60. #ifndef __QUICKDRAW__
  61. #include <Quickdraw.h>
  62. #endif
  63.  
  64. #ifndef __TYPES__
  65. #include <Types.h>
  66. #endif
  67.  
  68. //----------------------------------------------------------------------------------------
  69. // Constants
  70. //----------------------------------------------------------------------------------------
  71.  
  72. const OSType kSignature = 'SS00';                // Application signature
  73. const OSType kFileType = 'SF00';                // File-type code used for document files
  74.                                                 // created by this application
  75.  
  76.  
  77. //----------------------------------------------------------------------------------------
  78. // TNothingApplication:
  79. //----------------------------------------------------------------------------------------
  80.  
  81. class TNothingApplication : public TApplication
  82. {
  83.     MA_DECLARE_CLASS;
  84.     
  85. public:
  86.     virtual ~TNothingApplication();
  87.     
  88.     void INothingApplication();
  89.  
  90.     virtual TDocument* DoMakeDocument(CommandNumber itsCommandNumber, TFile* itsFile);
  91.         // Override
  92. };
  93.  
  94.  
  95. //----------------------------------------------------------------------------------------
  96. // TDefaultView:
  97. //----------------------------------------------------------------------------------------
  98.  
  99. class TDefaultView : public TView
  100. {
  101.     MA_DECLARE_CLASS;
  102.     
  103. public:
  104.     virtual ~TDefaultView();
  105.     
  106.     virtual void Draw(const VRect& area);
  107.         // Draws the view seen in the window. Every nonblank view MUST override this
  108.         // method.
  109. };
  110.  
  111.  
  112.  
  113. //========================================================================================
  114. // CLASS TNothingApplication
  115. //========================================================================================
  116. #undef Inherited
  117. #define Inherited TApplication
  118.  
  119. MA_DEFINE_CLASS_M1(TNothingApplication, TApplication);
  120.  
  121. //----------------------------------------------------------------------------------------
  122. // TNothingApplication destructor
  123. //----------------------------------------------------------------------------------------
  124.  
  125. TNothingApplication::~TNothingApplication()
  126. {
  127. }
  128.  
  129. //----------------------------------------------------------------------------------------
  130. // TNothingApplication::INothingApplication: 
  131. //----------------------------------------------------------------------------------------
  132.  
  133. void TNothingApplication::INothingApplication()
  134. {
  135.     IApplication(kFileType, kSignature);
  136.     
  137.     // So my view will be substituted when MacApp® creates the "default view"
  138.     
  139.     MA_REGISTER_SIGNATURE(TDefaultView, kStdDefaultView);
  140.  
  141.     // So we can create the view object by name
  142.     
  143.     MA_REGISTER_CLASS(TDefaultView)
  144. } // TNothingApplication::INothingApplication 
  145.  
  146. //----------------------------------------------------------------------------------------
  147. // TNothingApplication::DoMakeDocument: 
  148. //----------------------------------------------------------------------------------------
  149.  
  150. TDocument* TNothingApplication::DoMakeDocument(CommandNumber, TFile* /*itsFile*/)
  151. {
  152.     TDocument* aDocument = new TDocument;
  153.     
  154.     aDocument->IDocument();
  155.     
  156.     return aDocument;
  157. } // TNothingApplication::DoMakeDocument 
  158.  
  159.  
  160.  
  161. //========================================================================================
  162. // CLASS TDefaultView
  163. //========================================================================================
  164. #undef Inherited
  165. #define Inherited TView
  166.  
  167. MA_DEFINE_CLASS_M1(TDefaultView, TView);
  168.  
  169. //----------------------------------------------------------------------------------------
  170. // TDefaultView destructor
  171. //----------------------------------------------------------------------------------------
  172.  
  173. TDefaultView::~TDefaultView()
  174. {
  175. }
  176.  
  177. //----------------------------------------------------------------------------------------
  178. // TDefaultView::Draw: 
  179. //----------------------------------------------------------------------------------------
  180.  
  181. void TDefaultView::Draw(const VRect&)
  182. {
  183.     PenNormal();
  184.     PenSize(10, 10);
  185.     PenPat(&qd.dkGray);
  186.  
  187.     // Draw a dark gray frame
  188.     FrameRect(&GetQDExtent());
  189.  
  190.     // Set font and size for subsequent display in the window
  191.     TextFont(times);    // a nice outline font
  192.     TextSize(72);
  193.  
  194.     MoveTo(45, 90);
  195.  
  196.     // Draw the word 'MacApp®' in large type.
  197.     DrawString("\pMacApp®");
  198.  
  199.     // Restore the pen state.
  200.     PenNormal();
  201. } // TDefaultView::Draw 
  202.  
  203.  
  204.  
  205. //========================================================================================
  206. // GLOBAL Functions
  207. //========================================================================================
  208.  
  209. //----------------------------------------------------------------------------------------
  210. // main:
  211. //----------------------------------------------------------------------------------------
  212. #pragma push
  213. #pragma processor 68000
  214. #pragma segment Main
  215.  
  216. void main()
  217. {
  218.     InitUMacApp(3);                    // Initialize MacApp; 3 calls to MoreMasters
  219.  
  220.     TNothingApplication* aNothingApplication = new TNothingApplication;
  221.     aNothingApplication->INothingApplication();
  222.     aNothingApplication->Run();
  223. } // main
  224.  
  225. #pragma pop
  226.  
  227. //----------------------------------------------------------------------------------------
  228. // End of Nothing.cp
  229.  
  230. #pragma segment Inline
  231.